/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

function changyy() {
    var changyy = d3.select("body").append("div").classed("changyy", true).style({
        position: "absolute",
        width: "100%",
        height: "100%",
        left: "100%"
    });
    $(".dt_warp").css("position","absolute");
    $(".dt_warp").animate({left: "-100%"}, Transiacion);
    $(".changyy").animate({left: "0%", top: "0%"}, Transiacion);
    var sz_bg = changyy.append("div").classed("sz_bg", true).attr("id","sz_bg");
    var head = sz_bg.append("div").classed("datong_header", true);
    head.append("h1").html("常用语设置").classed("h_title", true);
    var go_back = head.append("div").classed("go_back", true);
    go_back.html("<i><img src =../../common/page/images/go_back_ico.png width =16 height=auto></i>返回");
    go_back.on(touch_s, function() {
        $(this).css("background-color", "#005ebf");
    });
	$('.userName').find('p').hide();
	var editButton=d3.select(".userName").append("div").classed("editButton", true).html('编辑').style({
		'font-size':'16px',
		'margin-right':'10px',
		'cursor':"pointer"
	});
	editButton.on(touch_e, function () {
		if($(this).html().indexOf("编辑") > -1){
			$(this).html('完成');
			$('.changyylir').animate({left:'10px'},300);
		}else{
			$(this).html('编辑');
			$('.changyylir').animate({left:'-100%'},300);
		}
	});
    go_back.on(touch_e, function() {
        $(this).css("background-color", "");
        $(".dt_warp").animate({left: "0px"}, Transiacion );
        $(".changyy").animate({left: "100%"}, Transiacion , function() {
            $(this).remove();
			$('.userName').find('p').show();
			$('.userName').find('.editButton').remove();
        });
    });
	function back1() {
        $(".dt_warp").animate({left: "0px"}, Transiacion );
        $(".changyy").animate({left: "100%"}, Transiacion , function() {
            $(this).remove();
			$('.userName').find('p').show();
			$('.userName').find('.editButton').remove();
        });
        Android.back = TempFunction.back;
    }
    Android.back = TempFunction.back1=back1;
  var sz=sz_bg.append("div").classed("datong_con ,datong_con2", true);
  //添加输入框
  var searchdiv=sz.append("div").classed("search",true).style({height:'auto',background:'white'});
  var cz_sjr=searchdiv.append("div").classed("cz_sjr",true).style({background:'none'});
  var sjr_input=cz_sjr.append("div").classed("sjr_input",true);
  sjr_input.append("input").attr("type","text").attr("placeholder","请输入您要添加的常用语内容");
  var addbutton=sjr_input.append("input").attr("type","button").attr("value","添加");
  addbutton.on(touch_e, function () {
	 if($(this).prev().val() == ''){
		 Prompt("请输入您要添加的常用语内容!", 1000);
	 }else{
		 var url=serverURL+'cmcp/user/addPhrase';
		 var self={
			'language':$(this).prev().val()
		　};
		 PostXF(url, self, function (dat) {
			 $(this).prev().val('');
			  inintlist();
		 },function(a,b,c){
			  Prompt("添加失败!", 1000);
		  });
		
	 }
  });
 //常用语列表
  var list=sz.append("div").classed("changlist",true).attr("id","changlist").style({
	  height:(height-100)+'px'
  });
  inintlist();
}
function inintlist(){
   $('.editButton').html('编辑');
  $('.changlist').html('');
  var changul=d3.select('.changlist').append("ul");
  var url =serverURL +"cmcp/user/findPhraseList";
  PostCP(url,{},function (dat) {
		if (dat) {
			for(var i=0;i<dat.length;i++){
				 var changli=changul.append("li").style({color:"#555","position":"relative"});
				 var lil=changli.append("div").classed("changyylil",true).html(dat[i].language);
				 var lir=changli.append("div").attr("id",dat[i].id).classed("changyylir",true).html('-').style({
					"margin-top":(($(lil.node()).height()-5)/2)+'px'	 
				});
				 lir.on(touch_e, function () {
					 var id=$(this).attr("id");
					  navigator.notification.confirm('您确定要删除此条常用语吗？', showConfirm, 'OA', ['取消', '确定']);
					  function showConfirm(button){
						  if(button == 2){
							    var url=serverURL+'cmcp/user/deletePhrase';
								 var self={
									'phraseId':id
								　};
								 PostXF(url, self, function (dat) {
									  inintlist();
								 },function(a,b,c){
									  Prompt("删除失败!", 1000);
								  });
						  }
					  }
				 });
			}
			 Yscroll = new iScroll("changlist", {hScrollbar: false, vScrollbar: false});
		}
  },function(a,b,c){
	  window.plugins.getIntent.hide();
	   Prompt("获取数据失败!", 1000);
	});
}